package route

import (
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/cors"
	"github.com/gofiber/fiber/v2/middleware/logger"
	"github.com/gofiber/fiber/v2/middleware/requestid"
	"github.com/gofiber/swagger"
	"github.com/kadycui/fiber-ci/api"
	_ "github.com/kadycui/fiber-ci/docs"
	"github.com/kadycui/fiber-ci/middleware"
)

// New create an instance of Book app route
func New() *fiber.App {
	app := fiber.New()

	app.Use(requestid.New())

	app.Use(cors.New())

	app.Use(logger.New(logger.Config{
		Format:     "${pid} ${time}  ${status} - ${method} ${path}\n",
		TimeFormat: "2006-01-02 15:04:05",
		TimeZone:   "Asia/Shanghai",
	}))

	app.Get("/swagger/*", swagger.HandlerDefault) // default

	// Generate Swagger documentation
	swaggerHandler := swagger.New(swagger.Config{
		URL:         "/swagger/doc.json",
		DeepLinking: false,
	})

	// Serve Swagger UI
	app.Get("/docs/*", swaggerHandler)

	v1 := app.Group("/api/v1")
	{

		// Lu
		v1.Get("/lu/:id", api.GetLuById)

		// Channel
		v1.Get("/channel/:id", api.GetChannelById)
		v1.Post("/channel/createjson/", api.CreateChannelJson)
		v1.Post("/channel/createalljson/", api.CreateAllChannelJson)

		// Group
		v1.Get("/group/:id", api.GetGroupById)

		// Su
		v1.Get("/su/:id", middleware.ApiKeyAuth, api.GetSuById)

	}

	return app
}
